<?php

/**
 * LayoutBehavior class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Monday, January 30, 2012. 09:21 AM
 */
class LayoutBehavior extends CBehavior {

	public function getMenu() {
		static $menu = null;

		if (!isset($menu)) {
			$user = Yii::app()->user;
			$notGuest = !$user->isGuest;
			$userModule = Yii::app()->getModule('user');
			$menu = array();
			$menu[] = array(
				'label'=>'Q&A',
				'url'=>array('/qa/question/index'),
			);
			$menu[] = array(
				'label'=>'Employee',
				'url'=>array('/employee/index'),
				'visible'=>$notGuest &&
				$user->checkAccess('Employee.Index'),
			);
			$menu[] = array(
				'label'=>'Holiday',
				'url'=>array('/holiday/index'),
				'visible'=>$notGuest &&
				$user->checkAccess('Holiday.Index'),
			);
			$menu[] = array(
				'label'=>'Rights',
				'url'=>array('/rights/assignment/view'),
				'visible'=>$user->isSuperuser,
			);
			$menu[] = array(
				'url'=>$userModule->loginUrl,
				'label'=>$userModule->t("Login"),
				'visible'=>$user->isGuest,
			);
			$menu[] = array(
				'url'=>$userModule->registrationUrl,
				'label'=>$userModule->t("Register"),
				'visible'=>$user->isGuest,
			);
			$menu[] = array(
			'url'=>$userModule->logoutUrl,
			'label'=>$userModule->t("Logout") . " ($user->name)",
			'visible'=>$notGuest,
			);
		}

		return $menu;
	}

	private $_assetsUrl;

	public function getAssetsUrl() {
		if ($this->_assetsUrl === null) {
			$path = Yii::getPathOfAlias("application.assets");
			$this->_assetsUrl = Yii::app()->assetManager->publish(
				$path, false, -1, YII_DEBUG
			);
		}
		return $this->_assetsUrl;
	}

}
